package com.dailyblue.java.project.smbms.stocklog.listener;

import com.alibaba.fastjson.JSONArray;
import com.dailyblue.java.project.smbms.stocklog.bean.StockLog;
import com.dailyblue.java.project.smbms.stocklog.service.StockLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Slf4j
@RocketMQMessageListener(topic = "STOCK", selectorExpression = "LOG", consumerGroup = "zhuoyue02")
public class StockLogListener implements RocketMQListener<String> {
    @Resource
    private StockLogService stockLogService;

    @Override
    public void onMessage(String s) {
        StockLog stockLog = JSONArray.parseObject(s, StockLog.class);
        log.info("订阅了RocketMQ的信息，内容是：{}",stockLog);
        stockLogService.saveStockLog(stockLog);
    }
}
